﻿using System;
using System.Windows.Forms;

namespace NhapXuatTon
{
    public partial class FormMain : Form
    {
        readonly Clsdatabase _cls = new Clsdatabase();
        private static FormMain _instance;
        private String MaSanPham {set;get;}
        private const int AddNew = 1;
        private const int Edit = 2;

        public FormMain()
        {
            _instance = this;
            InitializeComponent();
        }
       
        public static FormMain GetInstance()
        {
            return _instance ?? (_instance = new FormMain());
        }


        private void button2_Click(object sender, EventArgs e)
        {
            if (MaSanPham != null)
            {
                FormChiTiet.GetInstance(Edit, MaSanPham).Show();
            }
            else
            {
                MessageBox.Show("Hãy chọn 1 mã sản phẩm!!!");
            }
        }

        private void FormMain_Load(object sender, EventArgs e)
        {
            LoadDbToForm();
        }

        public void LoadDbToForm()
        {
            _cls.Loaddatagridview(dataGridView1, "Select MaSanPham as 'Mã Sản phẩm', DonViTinh as 'Đơn vị tính', " +
                "DonGia as 'Đơn giá', LuongDauKy as 'Lượng đầu kỳ', TienDauKy as 'Tiền đầu kỳ', "+
                "LuongNhap as 'Lượng nhập', TienNhap as 'Tiền Nhập', LuongXuat as 'Lượng Xuất', TienXuat as 'Tiền Xuất',"+
                "TonCuoiKy as 'Lượng tồn cuối kỳ', TienCuoiKy as 'Tiền tồn cuối kỳ' from BangChinh");            
        }


        private void GetSoThe(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int hang = e.RowIndex;           
                MaSanPham = dataGridView1.Rows[hang].Cells[0].Value.ToString();         
            }
            catch (Exception)
            { }
        }

        private void btnThemMoi_Click(object sender, EventArgs e)
        {
            FormChiTiet.GetInstance(AddNew,"").Show();          
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            
        }

        private void BtnShowClick(object sender, EventArgs e)
        {
            var month = cbThang.Text;
            var yearh = cbNam.Text;

        } 
    }
}
